package com.ashin.controller;

import com.ashin.entity.Account;
import com.ashin.repository.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Ashin
 */
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountRepository accountRepository;

    @RequestMapping("/create/{id}/{name}")
    public void create(@PathVariable("id") String id, @PathVariable("name") String name) {
        Account entity = new Account();
        entity.setAccountId(id);
        entity.setName(name);

        Account save = accountRepository.save(entity);
        System.out.println(save);
    }

    @RequestMapping("/delete/{id}")
    public void delete(@PathVariable("id") String id) {
        Account entity = new Account();
        entity.setAccountId(id);

        accountRepository.delete(entity);
    }

}
